home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part1 / 6393 < prev    next >
Encoding:
Text File  |  1996-08-05  |  2.8 KB  |  84 lines

  1. Path: hubcap.clemson.edu!hubcap!mjs
  2. From: mjs@hubcap.clemson.edu (M. J. Saltzman)
  3. Newsgroups: comp.lang.pl1,comp.lang.c
  4. Subject: Re: PL/I and C
  5. Date: 23 Feb 96 22:05:39 GMT
  6. Organization: Clemson University
  7. Message-ID: <mjs.825113139@hubcap>
  8. References: <4gh5ru$eng@goanna.cs.rmit.EDU.AU> <312CCEB2.4AB7@corp.dialog.com> <AD536AAB9668B76CD@mcdialb09.it.luc.edu> <312E363C.3CDE@corp.dialog.com>
  9. NNTP-Posting-Host: hubcap.clemson.edu
  10.  
  11. Paul Gorodyansky <paul_gorodyansky@corp.dialog.com> writes:
  12.  
  13. |Verne Arase wrote:
  14. |> 
  15. |> In article <312CCEB2.4AB7@corp.dialog.com>,
  16. |> Paul Gorodyansky <paul_gorodyansky@corp.dialog.com> wrote:
  17. |> 
  18. |>  >In PL/I, you can consider your source record as a string,
  19. |>  >or as SEVERAL different complex Structures, using Based variables.
  20. |>  >C has it, too,  but with a BIG limitation - if you want to put
  21. |>  >SEVERAL different 'masks' over your buffer, C allows ONLY simple
  22. |>  >variables as items of these structures, not Arrays !
  23. |> 
  24. |> Actually, this is incorrect.
  25. |> 
  26. |> In fact, if I recall correctly a pointer to x is implicitly an array.
  27.  
  28. I don't understand this remark at all.  A pointer to x is nothing like
  29. an array.  See the FAQ for a detailed discussion of the relationship
  30. between pointers and arrays.
  31.  
  32. |Sorry, you missed my point. If I want to have SEVERAL masks for THE SAME
  33. |area of memory, that is have SEVERAL DIFFERENT Structures overlaid my
  34. |buffer, C has a feature for this - a Union, where I can have members of
  35. |different Nature overlaid the same area of memory, BUT, unlike PL/I, an
  36. |Array CAN NOT be a member of a Union. But, it is always a case in our
  37.  
  38. This is a vicious lie (or at very least, an unfortunate
  39. misconception).  A field in a union can be anything that a field in a
  40. struct can be, incuding a bitfield.
  41.  
  42. |Text Processing - I want to look at my source record's buffer at some 
  43. |----
  44. |point of time, as at a structure like this:
  45. |  1 Patent_Info,
  46. |    2 Part_1,
  47. |      3 Patent_Number ...
  48. |      3 Date_Of_Application...
  49. |     ...
  50. |    2 Part_5,                               
  51. |      3 Opponents,                      or 3 Opponents(10),
  52. |        4 Name(10)...                         4 Name...
  53. |        4 Address(10)...                      4 Address 
  54. |                         
  55. |In C I CAN NOT do it, so I MUST find some 'work around' and my code's
  56.  
  57. union {
  58.   struct { 
  59.     char patent_number[10]; 
  60.     char date_of_application[6]; 
  61.   } part_1;
  62.  
  63.   /* ... */
  64.  
  65.   struct { 
  66.     struct { 
  67.       char name[80]; 
  68.       char address[4][80]; 
  69.     } opponent[10]; 
  70.   } part_5;
  71. } patent_info;
  72.  
  73. /* ... */
  74.  
  75. puts(patent_info.part_5.opponent[3].name);
  76.  
  77. |logic become more complex, less clear, and far from SPECS, because this
  78. |structure was given in SPECS. So, next person who will work his FIRST
  79. |time with this code, will have trouble.
  80. -- 
  81.         Matthew Saltzman
  82.         Clemson University Math Sciences
  83.         mjs@clemson.edu
  84.